<template>
  <div class="feedbackOfBiddingResults">
    <!--   头部   -->
    <FixedOperation class="text-right">
      <div class="flex items-center justify-between">
        <div class="leading-30px">
          <div class="inline-block">
            <svg-icon
              :icon-class="'svg_tbfk'"
              class="w-30px h-30px align-middle"
            />
            <span
              class="text-#000 leading-30px ml-10px text-16px font-bold align-bottom"
              >投标情况反馈</span
            >
          </div>
          <div
            v-if="bpmnStatus"
            class="inline-block text-15px ml-10px"
            style="vertical-align: bottom"
          >
            <i
              :class="
                bpmnStatus == '办结'
                  ? 'h-8px w-8px bg-#fe9400 inline-block rounded'
                  : bpmnStatus == '流程未发起'
                  ? 'h-8px w-8px bg-#ccc inline-block rounded'
                  : 'h-8px w-8px bg-#10d070 inline-block rounded'
              "
            ></i>
            {{ bpmnStatus }}
          </div>
        </div>
        <!-- 内容 -->
        <div class="text-right">
          <slot></slot>
          <el-button
            v-if="isExamine && biddingForm.biddingResult == '0'"
            plain
            type="primary"
            @click="handleSaveFn('examine')"
            >发起申请</el-button
          >
          <el-button
            v-if="isEdit"
            plain
            type="primary"
            @click="handleSaveFn('save')"
            >保存</el-button
          >
          <el-button plain type="primary" @click="handleCloseFn"
            >返回</el-button
          >
        </div>
      </div>
    </FixedOperation>
    <el-row class="mt-30px px-30px w-80%">
      <TitleName
        class="title mb-20px"
        icon="i-carbon-bookmark-filled"
        title="基本信息"
      ></TitleName>
      <el-form
        ref="ruleFormRef"
        :disabled="!isEdit"
        :model="biddingForm"
        :rules="formRules"
        label-position="right"
        label-width="150"
      >
        <el-row :gutter="grid">
          <el-col :span="gridCol">
            <el-form-item label="项目名称：" prop="proName">
              <el-input
                v-model="biddingForm.proName"
                clearable
                disabled
                maxlength="20"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="项目属性：" prop="proType">
              <el-radio-group v-model="biddingForm.proType" disabled>
                <el-radio
                  v-for="(dict, index) in project_properties"
                  :key="index"
                  :label="dict.value"
                  border
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="项目编号：" prop="proNum">
              <el-input
                v-model="biddingForm.proNum"
                clearable
                disabled
                maxlength="20"
                placeholder="请输入项目编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="归属单位：" prop="companyName">
              <el-input
                v-model="biddingForm.companyName"
                clearable
                disabled
                maxlength="20"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="归属人员：" prop="principal">
              <el-input
                v-model="biddingForm.principal"
                clearable
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="关联客户：" prop="customer">
              <el-input
                v-model="biddingForm.customer"
                clearable
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="客户联系人：" prop="cusLinkName">
              <el-input
                v-model="biddingForm.cusLinkName"
                clearable
                disabled
                maxlength="20"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="手机号码：" prop="phone">
              <el-input
                v-model="biddingForm.phone"
                clearable
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="招标结果:" prop="biddingResult">
              <el-radio-group
                v-model="biddingForm.biddingResult"
                :disabled="bidResult"
              >
                <el-radio :label="'1'" border>中标</el-radio>
                <el-radio :label="'0'" border>未中标</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="gridCol">
            <el-form-item label="项目规模：" prop="projectScale">
              <el-input
                v-model="biddingForm.projectScale"
                clearable
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 中标显示 -->
          <el-row v-if="biddingForm.biddingResult == '1'" :span="24">
            <el-col :span="gridCol">
              <el-form-item label="最终中标项目金额:" prop="biddingSum">
                <el-input
                  v-model="biddingForm.biddingSum"
                  clearable
                  maxlength="30"
                  placeholder="请输入最终中标项目金额"
                  ><template #append>万元</template></el-input
                >
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="预计实施日期:" prop="expImpTime">
                <el-date-picker
                  v-model="biddingForm.expImpTime"
                  clearable
                  placeholder="请选择预计实施日期"
                  style="width: 100%"
                  type="date"
                  value-format="YYYY-MM-DD HH:mm:ss"
                />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item class="fileIcon_style" label="中标通知书:">
                <el-upload
                  :before-upload="beforeAvatarUpload"
                  :http-request="handleFileChange"
                  :show-file-list="false"
                  accept=".rar, .pdf, .doc, .xls, .docx, .xlsx, .jpg, .png"
                  action="#"
                  class="upload-demo"
                >
                  <el-button
                    class="text-gray-700"
                    style="font-size: 14px"
                    type="default"
                    ><el-icon><UploadFilled /></el-icon
                    >上传中标通知书</el-button
                  >
                  <template #tip>
                    <div class="el-upload__tip" style="display: contents">
                      支持格式：.rar .pdf .doc .xls .docx .xlsx .jpg
                      .png，文件大小不能超过500kb
                    </div>
                  </template>
                </el-upload>
                <div class="text-14px mt-10px" style="width: 100%">
                  <div v-for="(item, index) in fileList" :key="item.fileId">
                    <a :href="item.url">{{ item.origFileName }}</a>
                    <el-button plain text @click="delFileName(index)"
                      >删除</el-button
                    >
                  </div>
                </div>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 未中标显示 -->
          <el-row v-else :span="24">
            <el-col :span="24">
              <el-form-item label="未中标原因:" prop="loseBidStatus">
                <el-radio-group v-model="biddingForm.loseBidStatus">
                  <el-radio
                    v-for="item in loseBidStatusOption"
                    :key="item.value"
                    :label="item.value"
                    >{{ item.label }}</el-radio
                  >
                </el-radio-group>
                <div
                  v-if="biddingForm.loseBidStatus == 2"
                  class="inline-block ml-10px"
                >
                  <el-input
                    v-model="biddingForm.wbCompanyName"
                    placeholder="请输入公司名称"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label="未中标原因分析（请详细分析）:"
                prop="loseBidReason"
              >
                <el-input
                  v-model="biddingForm.loseBidReason"
                  :rows="4"
                  placeholder="请输入未中标原因分析（请详细分析）"
                  type="textarea"
                />
              </el-form-item>
            </el-col>
            <el-col :span="gridCol">
              <el-form-item label="是否重新投标:" prop="rebid">
                <el-radio-group v-model="biddingForm.rebid">
                  <el-radio :label="'1'">是</el-radio>
                  <el-radio :label="'0'">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="gridCol">
              <el-form-item label="预计重新投标日期:" prop="expRebidTime">
                <el-date-picker
                  v-model="biddingForm.expRebidTime"
                  clearable
                  placeholder="请选择预计实施日期"
                  style="width: 100%"
                  type="date"
                  value-format="YYYY-MM-DD HH:mm:ss"
                />
              </el-form-item>
            </el-col>
            <el-col :span="gridCol">
              <el-form-item label="开标提醒：" prop="bidReminder">
                <el-select
                  v-model="biddingForm.bidReminder"
                  class="w-full"
                  clearable
                  placeholder="请选择开标提醒"
                >
                  <el-option
                    v-for="(dict, index) in reminder_opening"
                    :key="index"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="gridCol">
              <el-form-item label="提醒方式：" prop="checkbox">
                <el-checkbox-group v-model="biddingForm.checkbox">
                  <el-checkbox
                    v-for="(dict, index) in reminder_method"
                    :key="index"
                    :label="dict.value"
                  >
                    {{ dict.label }}</el-checkbox
                  >
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
    </el-row>
    <!-- 提交审批 -->
    <SubmissionProcess
      :dialog-param="examineParam"
      :flowOptions="flowOptions"
      @close="handleClose('examine')"
      @initiate="handleClose('initiate')"
    ></SubmissionProcess>
  </div>
</template>
<script name="BiddingResults" setup>
import { ElLoading } from 'element-plus'
import FixedOperation from '@/components/FixedOperation'
import {
  project_phase, //项目阶段
  project_properties, //项目属性
  business_attribute, //业务属性
  project_amount, //项目金额
  bidding_form, //招标形式
  reminder_opening, //开标提醒(提醒时间)
  reminder_method, //提醒方式
  companyOptions
} from '@/hooks/dict/useProject'
import useCommonStore from '@/store/modules/common'
import { uploadFile, delFile } from '@/api/salesManage/contractManage'
import { isMoneyEight } from '../module/formData'
import * as Api from '@/api/projectManage/project'
import { addManage, getLatestMsg } from '@/api/system/notice'
import { pushNotifications } from '@/hooks/notification/push'
import { format } from 'date-fns'
import useUserStore from '@/store/modules/user'
import { getNodeData } from '@/api/workflow/process'
/********* 流程  start*********/
import useTagsViewStore from '@/store/modules/tagsView'
import SubmissionProcess from '@/businessComponents/SubmissionProcess'
import { listProcess, getBusinessProStatus } from '@/api/workflow/process'
const examineParam = ref({}) // 传递的参数
const isExamine = ref(false) //是否可以审批(办理详情 访问的时候不能审批，编辑页面 改业务已经发起审批了就不能审批)
const flowOptions = ref([]) //该业务的流程数据
const router = useRouter()
const route = useRoute()
const isEdit = ref(true) //是否是流程详情。但是流程中不能编辑
const bpmnStatus = ref('')
const isWorkDetailPage = ref(false) //是否流程页面

/*** 流程 end*************/
const commonStore = useCommonStore()
// 用户数据
const userStore = useUserStore()
const { proxy } = getCurrentInstance()
const data = reactive({
  defaults: {},
  proMsgData: null,
  dialogFormVisible: true,
  loseBidStatusOption: [
    {
      label: '流标',
      value: '1'
    },
    {
      label: '其他公司',
      value: '2'
    }
  ],
  formRules: {
    proName: [
      {
        required: true,
        message: '项目名称不能为空',
        trigger: ['blur', 'change']
      }
    ],
    customer: [
      {
        required: true,
        message: '客户名称不能为空',
        trigger: ['blur', 'change']
      }
    ],
    proType: [
      {
        required: true,
        message: '项目属性不能为空',
        trigger: ['blur', 'change']
      }
    ],
    proNum: [{ required: true, message: '项目编号不能为空', trigger: 'blur' }],
    principal: [
      { required: true, message: '归属人员不能为空', trigger: 'blur' }
    ],
    biddingSum: [
      { required: true, message: '最终中标项目金额不能为空', trigger: 'blur' },
      { validator: isMoneyEight }
    ],
    biddingResult: [
      {
        required: true,
        message: '招标结果不能为空',
        trigger: ['blur', 'change']
      }
    ],
    projectScale: [
      { required: true, message: '项目规模不能为空', trigger: 'blur' }
    ],
    phone: [{ required: true, message: '手机号码不能为空', trigger: 'blur' }],
    companyName: [
      {
        required: true,
        message: '归属单位不能为空',
        trigger: ['blur', 'change']
      }
    ],
    cusLinkName: [
      {
        required: true,
        message: '客户联系人不能为空',
        trigger: ['blur', 'change']
      }
    ],
    bidResult: [
      {
        required: true,
        message: '招标结果不能为空',
        trigger: ['blur', 'change']
      }
    ],
    loseBidStatus: [
      {
        required: true,
        message: '未中标原因不能为空',
        trigger: ['blur', 'change']
      }
    ],
    loseBidReason: [
      {
        required: true,
        message: '未中标原因分析（请详细分析）不能为空',
        trigger: ['blur', 'change']
      }
    ],
    rebid: [
      {
        required: true,
        message: '是否重新投标不能为空',
        trigger: ['blur', 'change']
      }
    ]
  },
  biddingForm: {
    checkbox: []
  }
})
const {
  loseBidStatusOption,
  biddingOption,
  defaults,
  biddingForm,
  formRules,
  proMsgData
} = toRefs(data)
//表单内的栅格化设置
const grid = ref(20)
const gridCol = ref(12)
const bId = ref(null) //投标反馈结果id
const bidResult = ref(false)
const openLoading = ref(null) // 加载状态
const openLoadingFn = () => {
  openLoading.value = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(0, 0, 0, 0.7)'
  })
}
/**获取投标反馈结果详情 */
async function getBidding() {
  openLoadingFn()
  // 查询项目详情数据
  const response = await Api.getProInfoByBidId({ bidId: bId.value })
  biddingForm.value = {
    ...(response.data.pro || {}), //基本信息
    ...(response.data.finance || {}), //投标项目财务 信息
    ...(response.data.bidding || {}) //投标结果反馈
  }
  fileList.value = response.data.bidding?.sysAttachFiles2 || []
  // 判断中标结果是否只读
  if (biddingForm.value.biddingResult === '1') {
    bidResult.value = true
  } else {
    biddingForm.value.biddingResult = !biddingForm.value.biddingResult
      ? '1'
      : biddingForm.value.biddingResult
    if (biddingForm.value.loseBidReason) {
      bidResult.value = true
    } else {
      bidResult.value = false
    }
  }
  // 未中标原因:
  biddingForm.value.loseBidStatus = biddingForm.value.loseBidStatus
    ? biddingForm.value.loseBidStatus
    : '1'
  biddingForm.value.loseBidReason = biddingForm.value.loseBidReason
    ? biddingForm.value.loseBidReason
    : undefined
  biddingForm.value.rebid = biddingForm.value.rebid
    ? biddingForm.value.rebid
    : '1'

  const res = await getLatestMsg({
    businessId: '项目-投标-' + response.data.pro.projectId
  })
  if (res.code == 200 && res.data) {
    biddingForm.value.checkbox = res.data.reminderMethod.split(',')
    biddingForm.value.bidReminder = res.data.followType
  } else {
    biddingForm.value.checkbox = ['0']
  }
  let flowRes = await getNodeData(bId.value) //获取当前流程节点
  bpmnStatus.value = flowRes.data?.nowTaskName
  isEdit.value =
    flowRes.data == null || flowRes.data?.isFirst == 'Y' ? true : false
  openLoading.value.close()
}
// 获取表单字段
const getFormParam = () => {
  let param = {}
  if (biddingForm.value.biddingResult == 1) {
    if (
      JSON.stringify(fileList.value) == '[]' &&
      typeof fileList.value == 'object'
    ) {
      proxy.$modal.msgError('中标通知书必填')
      return false
    }
    //中标
    param = {
      bid: biddingForm.value.bid,
      projectId: biddingForm.value.projectId,
      biddingResult: biddingForm.value.biddingResult,
      expImpTime: biddingForm.value.expImpTime,
      sysAttachFiles: fileList.value || [],
      biddingSum: biddingForm.value.biddingSum || 0
    }
  } else {
    if (
      biddingForm.value.loseBidStatus == 2 &&
      !biddingForm.value.wbCompanyName
    ) {
      proxy.$modal.msgError('其他公司的名字必须填写')
      return false
    }
    const resp = bidOpeningMsg()
    if (!resp) {
      return
    }
    param = {
      bid: biddingForm.value.bid,
      projectId: biddingForm.value.projectId,
      biddingResult: biddingForm.value.biddingResult,
      expRebidTime: biddingForm.value.expRebidTime,
      loseBidReason: biddingForm.value.loseBidReason,
      loseBidStatus: biddingForm.value.loseBidStatus,
      rebid: biddingForm.value.rebid,
      wbCompanyName: biddingForm.value.wbCompanyName
    }
  }
  return param
}
/**流程 同意时调的保存 方法 */
const handleSave = async () => {
  return await handleSaveFn('flow')
}
/** 该业务需要调的 保存接口 */
const handleSaveFn = type => {
  return new Promise((resolve, reject) => {
    if (!isEdit.value) {
      // 如果不是第一环节不能调保存接口
      console.log('不是第一环节')
      resolve()
      return false
    }
    proxy.$refs['ruleFormRef'].validate(async valid => {
      if (!valid) {
        reject(new Error('Validation failed'))
        return false
      }
      let param = getFormParam()
      if (!param) {
        reject(new Error('Validation failed'))
        return false
      }
      try {
        await Api.biddingUpdate(param)
        if (
          biddingForm.value.rebid === '1' &&
          biddingForm.value.biddingResult != 1
        ) {
          const linkProjectId = biddingForm.value.projectId
          let url = `/sales/projectManage/addProject?id=${linkProjectId}&name=${biddingForm.value.proName}`
          proMsgData.value.url = url
          proMsgData.value.businessId = '项目-投标-' + linkProjectId
          await addManage(proMsgData.value)
        }
        if (type == 'examine') {
          await handleExamine()
        } else if (type != 'flow') {
          let hrefs = location.href.match(/workDetail/)
          if (!hrefs) {
            // 保存接口才有
            proxy.useReturn(
              '',
              () => {
                handleBack()
              },
              async () => {}
            )
          } else {
            proxy.$modal.msgSuccess('保存成功')
          }
        }
        // 接口请求成功，resolve
        resolve()
      } catch (e) {
        // 发生错误，reject
        reject(e)
      }
    })
  })
}
// 将 handleSave 暴露
defineExpose({
  handleSave
})
/*** 文件上传 start */
const fileList = ref([])
/**文件上传 限制条件
 *
 * @param {*} rawFile
 */
function beforeAvatarUpload(rawFile) {
  if (rawFile.size / 1024 / 1024 > 20) {
    proxy.$modal.msgError('单个文件不能超过20MB!')
    return false
  }
}
// 上传合同
async function handleFileChange(params) {
  let formData = new FormData()
  formData.append('file', params.file)
  try {
    const res = await uploadFile(formData)
    if (res.code === 200 && res.data) {
      fileList.value.push(res.data)
    }
  } catch (error) {
    proxy.$modal.msgError(error)
  }
}
// 删除文件
async function delFileName(index) {
  try {
    proxy.$modal.confirm('是否删除该文件').then(async () => {
      const file = fileList.value[index]
      const res = await delFile(file.fileName)
      if (res.code === 200) {
        fileList.value.splice(index, 1)
        proxy.$modal.msgSuccess(res.data)
      }
    })
  } catch (error) {
    proxy.$modal.msgError(error)
  }
}
/*****文件上传 end */
const emit = defineEmits(['close'])
// 返回
const handleCloseFn = () => {
  if (location.href.match(/projectDetails/)) {
    emit('close', 'bidding')
  } else {
    handleBack()
  }
}

function bidOpeningMsg() {
  if (biddingForm.value.rebid === '0') {
    return true
  }
  const obj = {}
  let resp = true
  const num = [0, 1, 3, 5, 7][Number(biddingForm.value.bidReminder)]
  const time =
    biddingForm.value.expRebidTime && (num || num === 0)
      ? format(
          new Date(
            new Date(biddingForm.value.expRebidTime).getTime() -
              num * 24 * 60 * 60 * 1000
          ),
          'yyyy-MM-dd 00:00:00'
        )
      : ''
  obj.receiver = (biddingForm.value.principalId || '')
    .toString()
    .replace(/U/gi, '')
  obj.content = `${biddingForm.value.proName}投标结果反馈,其中质保金：${biddingForm.value.qgAmount}万元,履约保证金：${biddingForm.value.pb}万元`
  obj.sendTime = time
  obj.reminderMethod =
    !biddingForm.value.checkbox ||
    (biddingForm.value.checkbox && biddingForm.value.checkbox.length === 0)
      ? ''
      : biddingForm.value.checkbox.toString()
  obj.impSign = '2'
  obj.serviceType = '0'
  obj.urgFlag = '1'
  obj.receiverName = biddingForm.value.principal
  obj.followType = biddingForm.value.bidReminder
    ? biddingForm.value.bidReminder
    : null
  // obj.followDate = biddingForm.value.bidOpeningTime
  obj.urlName = '前往详情'
  obj.title = `关于${biddingForm.value.proName}的投标结果反馈`
  obj.type = '0'
  obj.sender = userStore.user.nickName
  console.log(biddingForm.value.checkbox, 'biddingForm.value.checkbox.')
  const checkbox = biddingForm.value.checkbox
    ? biddingForm.value.checkbox.toString()
    : ''
  // if (
  //   (biddingForm.value.bidReminder || checkbox) &&
  //   !biddingForm.value.expRebidTime
  // ) {
  //   proxy.$modal.msgWarning('请选择预计重新投标日期')
  //   return false
  // }
  // if (
  //   (biddingForm.value.bidReminder || biddingForm.value.expRebidTime) &&
  //   !checkbox
  // ) {
  //   proxy.$modal.msgWarning('请选择提醒方式')
  //   return false
  // }

  // if (
  //   !biddingForm.value.bidReminder &&
  //   (biddingForm.value.expRebidTime || checkbox)
  // ) {
  //   proxy.$modal.msgWarning('请选择开标提醒')
  //   return false
  // }

  if (
    !biddingForm.value.bidReminder &&
    !checkbox &&
    !biddingForm.value.expRebidTime
  ) {
    obj.receiver = ''
    obj.receiverName = ''
  }
  // const result = pushNotifications(obj, ['followType', 'sendTime'])
  // if (!result) {
  //   proxy.$modal.msgWarning('开标消息提醒存在未填内容，请先填写完整')
  //   resp = false
  // } else {

  // }
  proMsgData.value = obj
  return true
}
/***************************业务流程 模块 start**************/
/*****审批模块  start*** */
/**
 * 提交审批 按钮
 发布需要的参数 examineParam 参数说明
  visible弹出框是否显示
  businessId //业务id
  businessName//业务名称（如：项目模块 businessName：项目名称）
  amount// 流程设计里面设计的条件参数值
  categoryCode //分类编码：项目1，订单2 客户3 	投标4
**
 */
const handleExamine = () => {
  console.log('examineParam.value.businessId')
  if (!examineParam.value.businessId) {
    // 没有业务id 是不能发起审批
    proxy.$modal.msgWarning('请重新发起审批')
    return false
  }
  examineParam.value.businessName = biddingForm.value.proName + '_投标反馈结果' //业务名称
  examineParam.value.amount = biddingForm.value.biddingSum || 0 //项目金额
  examineParam.value.categoryCode = '4' //分类编码：项目1，订单2 客户3 	投标4
  examineParam.value.visible = true
}
// 返回
const handleBack = () => {
  useTagsViewStore().delView(router.currentRoute.value)
  router.go(-1)
}
// 关闭
const handleClose = type => {
  switch (type) {
    case 'examine':
      //弹出框关闭
      examineParam.value.visible = false
      break
    case 'initiate':
      //审批 发起成功-关闭当前路由
      examineParam.value.visible = false
      handleBack()
      break
  }
}
/*****审批模块  end*** */
/**
 * 业务流程整体思路：
 * 1.查询该业务是否有流程
 * 2.根据该业务流程来判断
 * * 2.1没有流程-提示不能新建数据
 * * 2.2只有一条流程时，则不弹出框流程提交审核按钮隐藏，直接保存(得到返回的业务id) 现实下一环节人的显示及弹出框 -再发起
 * * 2.3多条流程时，点击保存(得到返回的业务id) ，再点击提交审核按钮，弹出框现实流程，直接保存(得到返回的业务id) 现实下一环节人的显示及弹出框 -再发起
 * @param {*} type  业务类型 项目是1 订单业务2 	客户模块业务3 投标4
 */
const initFlowFn = async type => {
  // 1.查询该业务是否有流程
  let comRes = await listProcess({ pageNum: 1, pageSize: 9999, category: type })
  flowOptions.value = comRes.rows || []
  // 2.根据
  if (JSON.stringify(flowOptions.value) == '[]') {
    //2.1 没有流程-提示不能发起
    isExamine.value = false
  } else {
    //2.2 投标反馈结果 特殊 所以不需要保存就可以提交审批  //2.3多条流程时
    isExamine.value = true
  }
}
// 编辑页面的时候 -》根据业务查询审批状态
const getBusinessProStatusFn = async () => {
  let statusRes = await getBusinessProStatus({
    businessId: bId.value
  })
  await initFlowFn(4) //业务类型 项目是1 订单业务2 	客户模块业务3 投标4
  if (statusRes.data.canStart) {
    // canStart false时 不能发起，true则可以发起
    isExamine.value = true
  } else {
    isExamine.value = false
  }
}
const props = defineProps({
  id: {
    type: String || Number
  }
})

watch(
  () => route.query,
  val => {
    if (
      route.query &&
      route.query.id &&
      !!location.href.match(/biddingResults/)
    ) {
      //编辑页面---------------
      bId.value = route.query && route.query.id
      examineParam.value.businessId = route.query && route.query.id
      isEdit.value = false
      getBidding()
      //根据业务查询审批状态x
      getBusinessProStatusFn()
    } else if (
      (props.id && !!location.href.match(/detail/)) ||
      (props.id && !!location.href.match(/workDetail/))
    ) {
      // 待办详情-访问--------------------
      bId.value = props.id //业务id
      examineParam.value.businessId = props.id
      isEdit.value = true
      getBidding()
      isWorkDetailPage.value = true
    }
  },
  {
    immediate: true
  }
)
/***************************业务流程 模块 end****************************************************************/
</script>
